package tota.tuples;

/**
 * <p>Title: TOTA</p>
 * <p>Description: TOTA</p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: DII - DISMI</p>
 * @author Marco Mamei
 * @version 1.0
 */

import tuplespace.tuples.*;

/* this tuple is a message, it does not remain in the network */
public class MessageTuple extends StructureTuple
{
 private static final int TTL = 200000000;


 protected void makeSubscriptions() {	 
  SensorTuple st = new SensorTuple("<sensor=clock><value=*>");
  st = (SensorTuple)tota.keyrd(st);
  int currentTime = Integer.parseInt(st.value);
  st = new SensorTuple("<sensor=clock><value="+(currentTime+TTL)+">");
  tota.subscribe(st,this,"ERASE");
 }

 /*****************************************************************************/
 /*                         REACTIVE COMPONENT                                */
 /*****************************************************************************/
 public void react(String reaction, String event) {
  if(reaction.equalsIgnoreCase("ERASE")) {
   System.out.println(tota.toString());
   tota.unsubscribe(Tuple.deserialize(event),this);
   //tota.delete(this);
   
  }
 }
}
